
#include "stdafx.h"
#include "mimosav2manager.h"
#include "mimosav2managerDlg.h"


#define	CFG_COMMON			_T("Common")

#define	DEF_SOUNDIN_VOLUME	_T("60")
#define	DEF_SOUNDOUT_VOLUME	_T("80")

#define	DEF_SERVER			_T("takip.is-by.us")
#define	DEF_STUN			_T("")


void Cmimosav2managerDlg::loadConfig()
{
	TCHAR szText[MAX_PATH] = {0,};
	DWORD dwCount;
	int nCount;

	dwCount = GetPrivateProfileString(CFG_COMMON, _T("SoundIn"), DEF_SOUNDIN_VOLUME, szText, _countof(szText), theApp.m_strIniFile);
	szText[dwCount] = NULL;
	GetDlgItem(IDC_EDIT_SOUNDIN)->SetWindowText(szText);

	dwCount = GetPrivateProfileString(CFG_COMMON, _T("SoundOut"), DEF_SOUNDOUT_VOLUME, szText, _countof(szText), theApp.m_strIniFile);
	szText[dwCount] = NULL;
	GetDlgItem(IDC_EDIT_SOUNDOUT)->SetWindowText(szText);

	dwCount = GetPrivateProfileString(CFG_COMMON, _T("Server"), DEF_SERVER, szText, _countof(szText), theApp.m_strIniFile);
	szText[dwCount] = NULL;
	GetDlgItem(IDC_EDIT_SERVER)->SetWindowText(szText);

	dwCount = GetPrivateProfileString(CFG_COMMON, _T("Stun"), DEF_STUN, szText, _countof(szText), theApp.m_strIniFile);
	szText[dwCount] = NULL;
	GetDlgItem(IDC_EDIT_STUN)->SetWindowText(szText);

	nCount = (int)GetPrivateProfileInt(CFG_COMMON, _T("BdCount"), 0, theApp.m_strIniFile);

	m_bIsSaveClientInfo = (BOOL)GetPrivateProfileInt(CFG_COMMON, _T("SaveClientInfo"), FALSE, theApp.m_strIniFile);

	for (int i=0; i<nCount; i++)
	{
		for (int j=0; j<3; j++)
		{
			CLIENTINFO ci = {0,};

			ci.dwUserId_ = ((i + 1) * 10) + (j + 1);
			memset(ci.szCallInfo_, 0, sizeof(ci.szCallInfo_));

			_stprintf_s(ci.szUsername, _countof(ci.szUsername), _T("%s%04d"), CLIENT_USERID_PREFIX, ci.dwUserId_);

			ci.bIsBatch = (BOOL)GetPrivateProfileInt(ci.szUsername, _T("bIsBatch"), 0, theApp.m_strIniFile);

			dwCount = GetPrivateProfileString(ci.szUsername, _T("szPassword"), _T("8288"), ci.szPassword, _countof(ci.szPassword), theApp.m_strIniFile);
			ci.szPassword[dwCount] = NULL;

			dwCount = GetPrivateProfileString(ci.szUsername, _T("szSoundIn"), _T("-1"), ci.szSoundIn, _countof(ci.szSoundIn), theApp.m_strIniFile);
			ci.szSoundIn[dwCount] = NULL;

			dwCount = GetPrivateProfileString(ci.szUsername, _T("szSoundOut"), _T("-1"), ci.szSoundOut, _countof(ci.szSoundOut), theApp.m_strIniFile);
			ci.szSoundOut[dwCount] = NULL;

			dwCount = GetPrivateProfileString(ci.szUsername, _T("szComport"), _T("-1"), ci.szComport, _countof(ci.szComport), theApp.m_strIniFile);
			ci.szComport[dwCount] = NULL;

			ci.bIsStart = FALSE;
			memset(ci.szSipState, 0, sizeof(ci.szSipState));
			memset(ci.szHfpState, 0, sizeof(ci.szHfpState));
			memset(ci.szCallState, 0, sizeof(ci.szCallState));
			memset(ci.szPhoneInfo, 0, sizeof(ci.szPhoneInfo));
			memset(ci.szCallTime, 0, sizeof(ci.szCallTime));

			m_aryInfo.Add(ci);
		}
	}
}

void Cmimosav2managerDlg::saveConfig()
{
	CString strText;

	GetDlgItem(IDC_EDIT_SOUNDIN)->GetWindowText(strText);
	WritePrivateProfileString(CFG_COMMON, _T("SoundIn"), strText, theApp.m_strIniFile);

	GetDlgItem(IDC_EDIT_SOUNDOUT)->GetWindowText(strText);
	WritePrivateProfileString(CFG_COMMON, _T("SoundOut"), strText, theApp.m_strIniFile);

	GetDlgItem(IDC_EDIT_SERVER)->GetWindowText(strText);
	WritePrivateProfileString(CFG_COMMON, _T("Server"), strText, theApp.m_strIniFile);

	GetDlgItem(IDC_EDIT_STUN)->GetWindowText(strText);
	WritePrivateProfileString(CFG_COMMON, _T("Stun"), strText, theApp.m_strIniFile);

	strText.Format(_T("%d"), m_aryInfo.GetCount() / 3);
	WritePrivateProfileString(CFG_COMMON, _T("BdCount"), strText, theApp.m_strIniFile);

	strText.Format(_T("%d"), m_bIsSaveClientInfo);
	WritePrivateProfileString(CFG_COMMON, _T("SaveClientInfo"), strText, theApp.m_strIniFile);

	if (m_bIsSaveClientInfo)
	{
		for (int i=0; i<m_aryInfo.GetCount(); i++)
		{
			const CLIENTINFO &ci = m_aryInfo.GetAt(i);

			WritePrivateProfileString(ci.szUsername, _T("bIsBatch"), (ci.bIsBatch ? _T("1") : _T("0")), theApp.m_strIniFile);

			WritePrivateProfileString(ci.szUsername, _T("szPassword"), ci.szPassword, theApp.m_strIniFile);

			WritePrivateProfileString(ci.szUsername, _T("szSoundIn"), ci.szSoundIn, theApp.m_strIniFile);

			WritePrivateProfileString(ci.szUsername, _T("szSoundOut"), ci.szSoundOut, theApp.m_strIniFile);

			WritePrivateProfileString(ci.szUsername, _T("szComport"), ci.szComport, theApp.m_strIniFile);
		}
	}
}
